package com.itheima.reggie.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.reggie.pojo.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author gakki
 * @create 2022/5/4 17:04
 */
@Mapper
public interface  OrdersMapper extends BaseMapper<Orders> {

    //@Select(value = "SELECT m.mon,count(s.mon) num,IFNULL(SUM(s.amount),0) total from months m LEFT JOIN (SELECT MONTH(order_time) mon,amount FROM orders WHERE YEAR(order_time) = YEAR(now())) s ON m.mon = s.mon GROUP BY m.mon;")
    @Select(value = "SELECT m.mon,count(MONTH(o.order_time)) num,IFNULL(o.amount,0) total FROM months m LEFT JOIN orders o ON YEAR(o.order_time) = YEAR(NOW()) AND MONTH(o.order_time) = m.mon GROUP BY m.mon;")
    List<Map> countByMonth();
}

